#!/usr/bin/env bash
APP="supershop-0.0.1"
SERVER_PORT="10080"

JARNAME="supershop-0.0.1-SNAPSHOT.jar"
REPODIR="/root/.jenkins/ws_gitee/target"
REPOJAR="${REPODIR}/${JARNAME}"

BACKDIR="/usr/working/deving/back/"

BASEDIR="/usr/working/deving"
JARFILE="${BASEDIR}/${JARNAME}"
PIDFILE="${BASEDIR}/${APP}.pid"
 
if [ -f $PIDFILE ]; then
    echo "pid file exists...." 
    PID=$(cat $PIDFILE)		# 将PID从文件中读取，并作为一个变量
    echo "KILL 进程"$PID	
    kill -9 $PID		# KILL 进程
    rm -rf $PIDFILE
fi

CURRENT_TIME=`date +%Y%m%d%H%M%S`;
echo "current time is $CURRENT_TIME"
mkdir -p ${BACKDIR}${CURRENT_TIME}
echo "backup apps..."
mv ${JARFILE} ${BACKDIR}${CURRENT_TIME}
cp ${REPOJAR} ${BASEDIR}

BUILD_ID=DONTKILLME

echo "启动jar:${JARFILE}"

cd ${BASEDIR}

nohup java -Xms512M -Xmx512M -jar ${JARFILE} --server.port=${SERVER_PORT} >> /${BASEDIR}/${APP}.nohup.out 2>&1 &
echo $! > ${PIDFILE}
PID=$(cat ${PIDFILE})
echo "新进程已经启动，进程号:"${PID}
echo "all be done,server is running..."


# test url,after seconds
# curl -X GET --header 'Accept: application/json' 'https://www.yogapro.cn/microshop/api/category/list?pageStart=1&pageSize=2&name=1'
